//
//  TopicListSectionHeader.m
//  BaseProject
//
//  Created by 王洋 on 2020/12/11.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "TopicListSectionHeader.h"

@implementation TopicListSectionHeader

+ (CGFloat)calculateHeightWithModel:(CommonPostModel *)model {
    
    return 95 + [Utilities getStringHeightWithText:model.content font:[UIFont systemFontOfSize:14] viewWidth:(TTScreenWidth - 28)] + 10;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.userIcon pp_clipCorners:UIRectCornerAllCorners radius:self.userIcon.frame.size.height/2];
    });
}

- (void)fillWithModel:(CommonPostModel *)model {

    [self.userIcon sd_setImageWithURL:[NSURL URLWithString:model.userHeadUrl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.userName.text = model.userNickName;
    self.timeLab.text = model.createTime;
    self.contentLab.text = model.content;
    
    [self.tagBtn setTitle:[NSString stringWithFormat:@" %@",model.themeTitle] forState:UIControlStateNormal];
    
    [self.evaBtn setTitle:[NSString stringWithFormat:@" %ld",(long)model.replyCount] forState:UIControlStateNormal];
    [self.thumbBtn setTitle:[NSString stringWithFormat:@" %ld",(long)model.likes] forState:UIControlStateNormal];
    
    if (model.isZan.length > 0) {
        [self.thumbBtn setImage:[UIImage imageNamed:@"tanhun_zan_sel"] forState:UIControlStateNormal];
        [self.thumbBtn setTitleColor:UIColorHex(0xFF4242) forState:UIControlStateNormal];
    } else {
        [self.thumbBtn setImage:[UIImage imageNamed:@"tanhun_zan"] forState:UIControlStateNormal];
        [self.thumbBtn setTitleColor:UIColorHex(0x333333) forState:UIControlStateNormal];
    }
    
}

//评价按钮
- (IBAction)evaluateAction:(id)sender {
    if (self.TopicListSectionHeaderBlock) {
        self.TopicListSectionHeaderBlock(TopicSectionHeaderActionType_eva);
    }

}

//点赞按钮
- (IBAction)thumbAction:(id)sender {
    if (self.TopicListSectionHeaderBlock) {
        self.TopicListSectionHeaderBlock(TopicSectionHeaderActionType_thumb);
    }
}

@end
